<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // object.defineProperty() 确定
    // 1.不能对数组的变化进行监听
    // 2.只能监听对象的某个属性，不能监听整个对象

    let obj = {
      name: 'zs',
      arr: [1, 2, 3]
    }

    obj = new Proxy(obj, {
      //target 目标对象
      //prop 访问的属性名
      get(target, prop) {
        console.log('get', target, prop)
        return target[prop]
      },
      set(target, prop, value) {
        console.log(value, '修改')
      }
    })
    console.log(obj.arr)
    obj.name = 'ls'
    obj.arr.push(10)
  </script>
</body>

</html>